/**
 * Created by Diego on 10/9/16.
 */
$(function () {
    var isBasicModified = false;
    var isExpectModified= false;
    var isEduModified= false;
    var isWorkModified=false;

    var time = new Date();
    var date = time.getFullYear()+"-"+(time.getMonth()+1);//当前年月
    var birthday = $("#birthday");
    if(birthday.val() ==""){
        birthday.val(date);
    }
	//工作经历时间默认当前年月
    $("#workTimeStart,#workTimeEnd").val(date);
	Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    	for (var k in o)
    	if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    	return fmt;
	}
    $.fn.datetimepicker.dates['zh-CN'] = {
        days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
        daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
        daysMin:  ["日", "一", "二", "三", "四", "五", "六", "日"],
        months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
        monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
        today: "今天",
        suffix: [],
        meridiem: ["上午", "下午"]
    };
    $('.date-input').datetimepicker({
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 4,//2:month,3:year,4:for the 10-year overview
        minView: 3,
        forceParse: 0,
        format: 'yyyy-mm',
        language:"zh-CN"
    }).on("dp.change dp.show changeDate", function (ev) {
        //获取当前日期框的id
        var parent = $(ev.target).parents(".group");
        var dateInputClassName = ev.target.className;
        var start = parent.find("input.start");
        var end = parent.find("input.end");
        var _time = new Date();
        var _date = _time.getFullYear()+"-"+(_time.getMonth()+1);//当前年月
        var className = ev.target.className;

        //不能超过当前年月
        if(ev.target.value>_date){
            ev.target.value = _date;
        }
        //如果结束时间已填  那么开始时间要小于结束时间  否则等于已填的结束时间
        if (dateInputClassName.indexOf("start")>0 && end.val() !== "") {
            if (ev.target.value > end.val()) {
                ev.target.value = end.val();
            }
        }

        //如果开始时间已填 那么结束时间要大于开始时间  否则等于已填的开始时间
        if (dateInputClassName.indexOf("end")>0 && start.val() !== "") {
            if (ev.target.value < start.val()) {
                ev.target.value = start.val();
            }
        }
        //验证有没有修改什么的
        if(className.indexOf('birthday')>0){
            isBasicModified = true;
            enableBtn($(".save-btn.basic"),"basic");
        }else if(className.indexOf('eduTime')>0){
            isEduModified = true;
            enableBtn($(".save-btn.edu"));
        }else if(className.indexOf('workTime')>0){
            isWorkModified = true;
            enableBtn($(".save-btn.job"));
        }

    });
	//修改基本信息
	$(".ed").click(function(){
		var parent   = $(this).parents(".common");
		var name     = $("#_name").html().trim(),
			phone    = $("#_phone").html().trim(),
			sex	     = $("#_sex").html().trim(),
			work     = $("#_workYear").html().trim().split("年")[0],
			ex_place = $("#_expectCity").html().trim().split(": ")[1],
			age		 = $("#_age").attr("data-birthday").trim();

			var ex_work = ($("#_expectJob").html().trim().split(": ")[1]+"").split(",");
			var len = ex_work.length;
			$("#name").val(name);
			$("#telephone").val(phone);
			$("#birthday").val(age);
			if(sex!==""){
				$("input[name='sex']").val(sex);
				$(".sex_select").each(function(){
					$(this).attr("data-sex")==sex ? $(this).addClass("selected") : $(this).removeClass("selected");
				});
			}
			$("#workYear option").each(function(){
                if($(this).val() == work){
                    $(this).prop("selected","selected");
                }
            });
			$("#expect_city option").each(function(){
				if($(this).val() == ex_place){
					$(this).prop("selected","selected");
				}
			});
			for(var i=0;i<len;i++){
				$(".work-list .item").each(function(n,val){
					if($(this).find(".skill-name").html().trim() == ex_work[i]){
						$(this).find("input").prop("checked",true);
					}
				})
			}
			if(len==2){
				$(".work-list input:not(:checked)").prop("disabled",true);
			}
		parent.slideToggle()
			  .next(".edit-content").slideToggle();
	});
	//取消编辑基本信息
	$(".cancel-btn").click(function(){
		$(".edit-content.b").slideToggle().prev().slideToggle();
	});
	//添加教育经历,工作经历
	$(".add-edu,.add-work").click(function(e){
		$(this).hide().next().show();
		var top = $(".interview-resume").scrollTop();
		if(e.currentTarget.className == 'add-work'){
			$(".interview-resume").scrollTop(top+400)
		}
	});
    /*--------------------     basic start      ---------------------------------*/
    //sex choice
    $(".sex_select").click(function () {
        $(".sex_select").removeClass("selected");
        $(this).addClass("selected");
        var sex = $(this).attr("data-sex");
        $("input[name='sex']").val(sex);
        isBasicModified = true;
        enableBtn($(".save-btn.basic"),"basic");
    });

    $("#workYear").change(function(){
        isBasicModified = true;
        enableBtn($(".save-btn.basic"),"basic");
    })
    //city choice
    var sf= [];
    sf[0] = ["浙江省","杭州|宁波|温州|嘉兴|湖州|绍兴|金华|衢州|舟山|台州|丽水"];
    sf[1] = ["北京市","东城|西城|崇文|宣武|朝阳|丰台|石景山|海淀|门头沟|房山|通州|顺义|昌平|大兴|平谷|怀柔|密云|延庆"];
    sf[2] = ["上海市","黄浦|卢湾|徐汇|长宁|静安|普陀|闸北|虹口|杨浦|闵行|宝山|嘉定|浦东|金山|松江|青浦|南汇|奉贤|崇明"];
    sf[3] = ["天津市","和平|东丽|河东|西青|河西|津南|南开|北辰|河北|武清|红挢|塘沽|汉沽|大港|宁河|静海|宝坻|蓟县"];
    sf[4] = ["重庆市","万州|涪陵|渝中|大渡口|江北|沙坪坝|九龙坡|南岸|北碚|万盛|双挢|渝北|巴南|黔江|长寿|綦江|潼南|铜梁 |大足|荣昌|壁山|梁平|城口|丰都|垫江|武隆|忠县|开县|云阳|奉节|巫山|巫溪|石柱|秀山|酉阳|彭水|江津|合川|永川|南川"];
    sf[5] = ["河北省","石家庄|邯郸|邢台|保定|张家口|承德|廊坊|唐山|秦皇岛|沧州|衡水"];
    sf[6] = ["山西省","太原|大同|阳泉|长治|晋城|朔州|吕梁|忻州|晋中|临汾|运城"];
    sf[7] = ["内蒙古自治区","呼和浩特|包头|乌海|赤峰|呼伦贝尔盟|阿拉善盟|哲里木盟|兴安盟|乌兰察布盟|锡林郭勒盟|巴彦淖尔盟|伊克昭盟"];
    sf[8] = ["辽宁省","沈阳|大连|鞍山|抚顺|本溪|丹东|锦州|营口|阜新|辽阳|盘锦|铁岭|朝阳|葫芦岛"];
    sf[9] = ["吉林省","长春|吉林|四平|辽源|通化|白山|松原|白城|延边"];
    sf[10] = ["黑龙江省","哈尔滨|齐齐哈尔|牡丹江|佳木斯|大庆|绥化|鹤岗|鸡西|黑河|双鸭山|伊春|七台河|大兴安岭"];
    sf[11] = ["江苏省","南京|镇江|苏州|南通|扬州|盐城|徐州|连云港|常州|无锡|宿迁|泰州|淮安"];
    sf[12] = ["安徽省","合肥|芜湖|蚌埠|马鞍山|淮北|铜陵|安庆|黄山|滁州|宿州|池州|淮南|巢湖|阜阳|六安|宣城|亳州"];
    sf[13] = ["福建省","福州|厦门|莆田|三明|泉州|漳州|南平|龙岩|宁德"];
    sf[14] = ["江西省","南昌市|景德镇|九江|鹰潭|萍乡|新馀|赣州|吉安|宜春|抚州|上饶"];
    sf[15] = ["山东省","济南|青岛|淄博|枣庄|东营|烟台|潍坊|济宁|泰安|威海|日照|莱芜|临沂|德州|聊城|滨州|菏泽"];
    sf[16] = ["河南省","郑州|开封|洛阳|平顶山|安阳|鹤壁|新乡|焦作|濮阳|许昌|漯河|三门峡|南阳|商丘|信阳|周口|驻马店|济源"];
    sf[17] = ["湖北省","武汉|宜昌|荆州|襄樊|黄石|荆门|黄冈|十堰|恩施|潜江|天门|仙桃|随州|咸宁|孝感|鄂州"];
    sf[18] = ["湖南省","长沙|常德|株洲|湘潭|衡阳|岳阳|邵阳|益阳|娄底|怀化|郴州|永州|湘西|张家界"];
    sf[19] = ["广东省","广州|深圳|珠海|汕头|东莞|中山|佛山|韶关|江门|湛江|茂名|肇庆|惠州|梅州|汕尾|河源|阳江|清远|潮州|揭阳|云浮"];
    sf[20] = ["广西壮族自治区","南宁|柳州|桂林|梧州|北海|防城港|钦州|贵港|玉林|南宁地区|柳州地区|贺州|百色|河池"];
    sf[21] = ["海南省","海口|三亚"];
    sf[22] = ["四川省","成都|绵阳|德阳|自贡|攀枝花|广元|内江|乐山|南充|宜宾|广安|达川|雅安|眉山|甘孜|凉山|泸州"];
    sf[23] = ["贵州省","贵阳|六盘水|遵义|安顺|铜仁|黔西南|毕节|黔东南|黔南"];
    sf[24] = ["云南省","昆明|大理|曲靖|玉溪|昭通|楚雄|红河|文山|思茅|西双版纳|保山|德宏|丽江|怒江|迪庆|临沧"];
    sf[25] = ["西藏自治区","拉萨|日喀则|山南|林芝|昌都|阿里|那曲"];
    sf[26] = ["陕西省","西安|宝鸡|咸阳|铜川|渭南|延安|榆林|汉中|安康|商洛"];
    sf[27] = ["甘肃省","兰州|嘉峪关|金昌|白银|天水|酒泉|张掖|武威|定西|陇南|平凉|庆阳|临夏|甘南"];
    sf[28] = ["宁夏回族自治区","银川|石嘴山|吴忠|固原"];
    sf[29] = ["青海省","西宁|海东|海南|海北|黄南|玉树|果洛|海西"];
    sf[30] = ["新疆维吾尔族自治区","乌鲁木齐|石河子|克拉玛依|伊犁|巴音郭勒|昌吉|克孜勒苏柯尔克孜|博尔塔拉|吐鲁番|哈密|喀什|和田|阿克苏"];
    sf[31] = ["香港特别行政区","香港特别行政区"];
    sf[32] = ["澳门特别行政区","澳门特别行政区"];
    sf[33] = ["台湾省","台北|高雄|台中|台南|屏东|南投|云林|新竹|彰化|苗栗|嘉义|花莲|桃园|宜兰|基隆|台东|金门|马祖|澎湖"];
    sf[34] = ["其它","北美洲|南美洲|亚洲|非洲|欧洲|大洋洲"];
    var pro = $("#pro").val();
    fillCity(pro);
    $("#pro").change(function(e){
        var that = this;
        isBasicModified = true;
        fillCity($(that).val());
        enableBtn($(".save-btn.basic"),"basic");
    });
    $("#city").change(function () {
        enableBtn($(".save-btn.basic"),"basic");
    });
    $("#expect_city").change(function(){
        if($(".work-list input:checked").length>0){
            enableBtn($(".save-btn.basic"));
        }
        isEduModified = true;
    });
    function fillCity(v){
        var _city = $("#city").attr("data-city");
        sf.forEach(function(val,n){
            var c = "";
            if(v == val[0]){
                var l = val[1].split("|");
                l.forEach(function(val,n){
                    if(val==_city){
                        c+="<option selected>"+val+"</option>";
                    }else {
                        c += "<option>" + val + "</option>"
                    }
                });
                $('#city').html(c);
                return;
            }
        })
    }

    //save basic info
    $("#basic").bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields:{
            realname: {
                validators: {
                    notEmpty: {
                        message: '姓名不能为空'
                    },
                    callback:{
                        callback: function (val,validator) {
                            isBasicModified = true;
                            enableBtn($(".save-btn.basic"),"basic");
                            return val !== "" ? true : false;
                        }
                    }
                }
            },
            phone_number:{
                validators: {
                    notEmpty: {
                        message: '手机号不能为空'
                    },
                    regexp: {
                        regexp: /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/,
                        message: '请输入正确的手机号码!'
                    },
                    callback:{
                        callback:function(val,validator){
                            var reg = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
                            isBasicModified = true;

                            enableBtn($(".save-btn.basic"),"basic");
                            return reg.test(val);
                        }
                    }
                }
            }
        }
    }).on('success.form.bv', function(e) {
        // Prevent form submission
        e.preventDefault();
        // Get the form instance
        var $form = $(e.target);

        // Get the BootstrapValidator instance
        var bv = $form.data('bootstrapValidator');
		var work=[];
		$(".work-list input:checked").each(function(n,target){
            work.push(target.value);
        });
		var name 	 = $("#name").val(),
			sex  	 = $("input[name='sex']").val(),
			age  	 = (new Date().getFullYear())-$("#birthday").val().split("-")[0],
			workYear = $("#workYear").val(),
			pro		 = $("#pro").val(),
			city	 = $("#city").val(),
			phone	 = $("#telephone").val(),
			ex_city  = $("#expect_city").val();
        // Use Ajax to submit form data
        $.post($form.attr('action'), $form.serialize()+"&&expect_job="+ work.join(","), function(result) {
            if(result.suc){
                isBasicModified = false;//提交后改为未修改状态
                saveResult("保存成功!");
                disabledBtn($(".save-btn.basic"));
                var _city = $("#city").val();
				$("#city").attr("data-city",_city);
				$("#_name").html(name);
				$("#_phone").html(phone);
				//$("#_sex").html(sex);
				//$("#_age").html(age+"岁").attr("date-birthday",$("#birthday").val());
				//$("#_workYear").html(workYear+"年工作经验");
				$(".basic-sec").html('<span id="_sex">'+sex+'</span><span> | </span><span id="_age" data-birthday="'+$("#birthday").val()+'">'+age+'岁</span><span> | </span><span id="_workYear">'+workYear+'年工作经验</span><span> | </span>')
				$("#_city").html("目前所在城市："+pro+" | "+city);
				$("#_expectCity").html("期望工作地点："+ex_city);
				$("#_expectJob").html("期望工作岗位："+work);
				lastUpdate();
				$(e.currentTarget).parent().slideToggle().prev().slideToggle();	
				result.resumeisok ? $(".preview").removeAttr("disabled") : $(".preview").attr("disabled","disabled");
				
            }else{
                saveResult("保存失败,请重新尝试");
            }
        }, 'json');
    });


    //work check max 2

    // if loading and check num 2
    var saveBtn = $(".save-btn.work");
    var inputNotChecked = $(".work-list input:not(:checked)");
    var workCheckCount = $(".work-list input:checked").length;
    if(workCheckCount==2){
        inputNotChecked.prop("disabled",true);
    }

    $(".work-list input").click(function(){
        isExpectModified = true;
        var inputNotChecked = $(".work-list input:not(:checked)");
        var maxSize=$(".work-list input:checked").length;
        if(maxSize>0){
            enableBtn($(".save-btn.basic"));
        }else{
            disabledBtn($(".save-btn.basic"));
        }
        if(maxSize==2){
            inputNotChecked.attr("disabled",true);
        }else{
            inputNotChecked.attr("disabled",false);
        }
    });
    
    /*--------------------     basic end      ---------------------------------*/

    //time choice now
    $("input.now").click(function () {
        var time = new Date();
        var date = time.getFullYear()+"-"+(time.getMonth()+1);
        var end  = $(this).parents(".inline").prev().find("input.end").val();
        if($(this).prop("checked")){
            $(this).parents(".inline").prev().css("visibility","hidden").find("input.end").val(date);
        }else{

            $(this).parents(".inline").prev().removeAttr("style").find("input.end").val(end == "" ? "" : end);
        }
    });
	//update time
	function lastUpdate(){
		var date = new Date().Format("yyyy-MM-dd hh:mm:ss");
		$("#_lastUpdate").html("最后更新时间 "+date);		
	}
	//del info
    $(document).on("click",'.del-edu,.del-job', function (e) {
        if(confirm("确定删除吗?")){
			var id=$(this).attr("data-id");
			var that=this;
            //do something
            $.ajax({
				url:$(that).attr("class").indexOf("del-edu") >= 0? "/resume/del_edu": "/resume/del_work",
				type:"post",
				dataType:"json",
				data:{
					id:id,
					_token:$("input[name='_token']").first().val()
				},
				success:function(res){
					if(res.suc){
						$(that).parents(".edu-item").animate({"opacity":0}).slideUp(function(){
              			  $(this).remove();
           				 });
						lastUpdate();
						saveResult("删除成功!");	
						res.resumeisok ? $(".preview").removeAttr("disabled") : $(".preview").attr("disabled","disabled");
					}
				}
            });
         }
    });
   
	/*--------------------     edu start      ---------------------------------*/

    //save edu info
    $("#edu").bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields:{
            school: {
                validators: {
                    notEmpty: {
                        message: '学校不能为空'
                    },
                    callback:{
                        callback: function (val,validator) {
                            isEduModified = true;
                            enableBtn($(".save-btn.edu"));

                            return val!==""?true:false;
                        }
                    }
                }
            },
            major:{
                validators: {
                    notEmpty: {
                        message: '专业不能为空'
                    },
                    callback:{
                        callback: function (val,validator) {
                            isEduModified = true;
                            enableBtn($(".save-btn.edu"));
                            return val!==""?true:false;
                        }
                    }
                }
            }
        }
    }).on('success.form.bv', function(e) {
        // Prevent form submission
        e.preventDefault();

        // Get the form instance
        var $form = $(e.target);

        // Get the BootstrapValidator instance
        var bv = $form.data('bootstrapValidator');
        // Use Ajax to submit form data
        $.post($form.attr('action'), $form.serialize(), function(result) {
            if(result.suc){
				$(".edu.common > .content").append(eduHTML(result.data));
				$(".add-edu").show();
                isEduModified = false;//提交后改为未修改状态
                saveResult("保存成功!");
                disabledBtn($(".save-btn.edu"));
				lastUpdate();
                $form.data('bootstrapValidator').resetForm(true);
                $(".edit-content.edu").hide();
				result.resumeisok ? $(".preview").removeAttr("disabled") : $(".preview").attr("disabled","disabled");

            }else{
                saveResult("保存失败。");
            }
        }, 'json');
    });
	//edit edu info
	$(document).on("click",".edit-edu",function(e){
		if($(e.currentTarget).parents(".content").parent(".common").find(".exp-edit .content").hasClass("active")){
			return;
		}
		var parent 		= $(this).parents(".edu-item"),
			school 		= parent.find(".mid").html(),//xuexiao  gongsi
			major  		= parent.find("div.fl").html().split(",")[0],//zhuangye  zhiwei
			degree 		= parent.find("div.fl").html().split(",")[1],//xueli
			s_time 		= parent.find(".shijian").html().split(" ~ ")[0],//kaishishijian
			e_time 		= parent.find(".shijian").html().split(" ~ ")[1],//jieshushijian
			id	   = $(this).attr("data-id");
            //set edit value
			$("#eduEditId").val(id);
            $("#schoolEdit").val(school);
            $("#educationEdit option").each(function(){
                if($(this).val() == degree){
                    $(this).prop("selected","selected");
                }
            });
            $("#eduTimeStartEdit").val(s_time);
            $("#eduTimeEndEdit").val(e_time);
            $("#majorEdit").val(major);
			$("#eduEdit .content").show().addClass("active");//已经存在编辑 其他不能再点
            $("#schoolEdit").focus();
		$(this).parents(".edu-item").remove();
	});
	//edit edu info
	$(document).on("click",".edit-job",function(e){
		if($(e.currentTarget).parents(".content").parent(".common").find(".exp-edit .content").hasClass("active")){
			return;
		}
		var parent 		= $(this).parents(".edu-item"),
			school 		= parent.find(".mid").html(),//xuexiao  gongsi
			major  		= parent.find("div.fl").html().split(",")[0],//zhuangye  zhiwei
			degree 		= parent.find("div.fl").html().split(",")[1],//xueli
			s_time 		= parent.find(".shijian").html().split(" ~ ")[0],//kaishishijian
			e_time 		= parent.find(".shijian").html().split(" ~ ")[1],//jieshushijian
			description = parent.find(".description").html().trim(),//gongzuomiaoshu
			id	   = $(this).attr("data-id");

			$("#expEdit").val(id);
            $("#companyEdit").val(school);
            $("#jobEdit").val(major);
            $("#workTimeStartEdit").val(s_time);
            $("#workTimeEndEdit").val(e_time);
            $("#workDetailEdit").html(description);
			$("#workEdit .content").show().addClass("active");
            $("#companyEdit").focus();
        
		$(this).parents(".edu-item").remove();
	});
    //save edu edit info
    $("#eduEdit").bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields:{
            schoolEdit: {
                validators: {
                    notEmpty: {
                        message: '学校不能为空'
                    },
					callback:{
                        callback: function (val,validator) {
                            return val!==""?true:false;
                        }
                    }
                }
            },
            majorEdit:{
                validators: {
                    notEmpty: {
                        message: '专业不能为空'
                    },
					callback:{
                        callback: function (val,validator) {
                        return val!==""?true:false;
                    	}
					}
                }
            }
        }
    }).on('success.form.bv', function(e) {
        e.preventDefault();
        var $form = $(e.target);
		$.ajax({
			url:$form.attr('action'),
			type:"post",
			dataType:'json',
			data:{
				_token:$("input[name='_token']").first().val(),
				school:$("#schoolEdit").val(),
				edu_bg:$("#educationEdit").val(),
				begin_at:$("#eduTimeStartEdit").val(),
				end_at:$("#eduTimeEndEdit").val(),
				major:$("#majorEdit").val(),
				id:$("#eduEditId").val()
			},
			success:function(result){
				if(result.suc){
					$(".edu.common>.content").append(eduHTML(result.data));
					$(".exp-edit.edu .content").hide().removeClass("active");
					lastUpdate();
					saveResult("保存成功!");
					result.resumeisok ? $(".preview").removeAttr("disabled") : $(".preview").attr("disabled","disabled");
				}
			}
		});
    });


    function eduHTML(d){
        return (
			'<div class="edu-item">'+
        		'<div class="edit fr">'+
            		'<a href="javascript:;" class="edit-edu fl" data-id="'+d.id+'" title="编辑教育经历"><i class="iconfont icon-shezhi"></i></a>'+
            		'<a href="javascript:;" class="del-edu" data-id="'+d.id+'" title="删除教育经历"><i class="iconfont icon-lajitong"></i></a>'+
        		'</div>'+
        		'<div class="mid">'+d.school+'</div>'+
        		'<div class="fl">'+d.major+','+d.edu_bg+'</div>'+
        		'<div class="fr shijian">'+d.begin_at+' ~ '+d.end_at+'</div>'+
        		'<div class="clearfix"></div>'+
        		'<hr style="border-style: dashed; margin: 13px 0">'+
    		'</div>' 
        )
    }

    /*--------------------     edu end      ---------------------------------*/



    /*--------------------     job start      ---------------------------------*/


    //save job edit info

    $("#workEdit").bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields:{
            companyEdit: {
                validators: {
                    notEmpty: {
                        message: '您之前的工作单位名称?'
                    },
					callback:{
                        callback: function (val,validator) {
                            return val!==""?true:false;
                        }
                    }
                }
            },
            jobEdit:{
                validators: {
                    notEmpty: {
                        message: '您之前的工作职位是什么?'
                    },
					callback:{
                        callback: function (val,validator) {
                            return val!==""?true:false;
                        }
                    }
                }
            },
            workDetailEdit:{
                validators: {
                    notEmpty: {
                        message: '项目经验越多越好!'
                    },
					callback:{
                        callback: function (val,validator) {
                            return val!==""?true:false;
                        }
                    }
                }
            }

        }
    }).on('success.form.bv', function(e) {
        e.preventDefault();
        var $form = $(e.target);
		$.ajax({
			url:$form.attr('action'),
			type:'post',
			dataType:'json',
			data:{
				_token:$("input[name='_token']").first().val(),
				company:$("#companyEdit").val(),
				job	   :$("#jobEdit").val(),
				begin_at:$("#workTimeStartEdit").val(),
				end_at:$("#workTimeEndEdit").val(),
				exp:$("#workDetailEdit").val(),
				id:$("#expEdit").val()
			},
			success:function(result){
				 if(result.suc){
					saveResult("修改成功!");
					$(".work.common>.content").append(jobHtml(result.data));
					$(".exp-edit.work .content").hide().removeClass("active");
					lastUpdate();
					result.resumeisok ? $(".preview").removeAttr("disabled") : $(".preview").attr("disabled","disabled");
				}

			}
		})
	});
    //save job info
    $("#work").bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields:{
            company: {
                validators: {
                    notEmpty: {
                        message: '您之前的工作单位名称?'
                    },
                    callback:{
                        callback: function (val, validator) {
                            isWorkModified = true;
                            enableBtn($(".save-btn.job"));
                            return val!=="" ? true : false;
                        }
                    }
                }
            },
            job:{
                validators: {
                    notEmpty: {
                        message: '您之前的工作职位是什么?'
                    },
                    callback:{
                        callback: function (val, validator) {
                            isWorkModified = true;
                            enableBtn($(".save-btn.job"));
                            return val!=="" ? true : false;
                        }
                    }
                }
            },
            exp:{
                validators: {
                    notEmpty: {
                        message: '项目经验不能为空'
                    },
                    callback:{
                        callback: function (val, validator) {
                            isWorkModified = true;
                            enableBtn($(".save-btn.job"));
                            return val!=="" ? true : false;
                        }
                    }
                }
            }

        }
    }).on('success.form.bv', function(e) {
        // Prevent form submission
        e.preventDefault();
		if($("#workDetailEdit").val()==""){return;}
        // Get the form instance
        var $form = $(e.target);
        // Get the BootstrapValidator instance
        var bv = $form.data('bootstrapValidator');
        // Use Ajax to submit form data
        $.post($form.attr('action'), $form.serialize(), function(result) {
            if(result.suc){
                isWorkModified = false;//提交后改为未修改状态
                saveResult("保存成功!");
				$(".add-work").show();
                disabledBtn($(".save-btn.job"));
                $(".work.common > .content").append(jobHtml(result.data));
                $('#work').data('bootstrapValidator').resetForm(true);
				$(".edit-content.work").hide();
				lastUpdate();
				result.resumeisok ? $(".preview").removeAttr("disabled") : $(".preview").attr("disabled","disabled");
            }else{
                saveResult("保存失败");
            }
        }, 'json');
    });

    function jobHtml(d){
        return (
       		'<div class="edu-item">'+
        		'<div class="edit fr">'+
            		'<a href="javascript:;" class="edit-job fl" data-id="'+d.id+'" title="编辑教育经历"><i class="iconfont icon-shezhi"></i></a>'+
            		'<a href="javascript:;" class="del-job" data-id="'+d.id+'" title="删除教育经历"><i class="iconfont icon-lajitong"></i></a>'+
        		'</div>'+
        		'<div class="mid">'+d.company+'</div>'+
        		'<div class="fl">'+d.job+'</div>'+
        		'<div class="fr shijian">'+d.begin_at+' ~ '+d.end_at+'</div>'+
        		'<div class="clearfix"></div>'+
				'<div class="description">'+d.exp+'</div>'+
        		'<hr style="border-style: dashed; margin: 13px 0">'+
    		'</div>'  
		)
    }

    /*--------------------     job start      ---------------------------------*/
    function enableBtn(obj,str){
		if(str=="basic"){
			var checkCount = $(".work-list input:checked").length;
			if(checkCount == 0){
				return;
			}
		}
        obj.removeClass("disabled").addClass("enabled").removeAttr("disabled");
    }
    function disabledBtn(obj){
        obj.removeClass("enabled").addClass("disabled").attr("disabled","disabled");
    }

    function saveResult(html){
        $(".alert strong").html(html);
        $(".alert").slideDown(function(){
            var that = this;
            setTimeout(function(){
                $(that).slideUp()
            },1000)
        });
    }
});
